package com.helloworld.chat.action;

import com.helloworld.chat.entity.Group;
import com.helloworld.chat.entity.User;
import com.helloworld.chat.service.GroupService;
import com.opensymphony.xwork2.ModelDriven;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by xdzy on 2017/6/28.
 */
@Controller
@Scope("prototype")
public class GroupAction implements ModelDriven<Group>{
    private Group group;
    private GroupService groupService;
    private String result;
    @Autowired
    public void setGroupService(GroupService groupService) {
        this.groupService = groupService;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public String groupList(){
        HttpServletRequest request= ServletActionContext.getRequest();
        int uid= ((User)(request.getSession().getAttribute("loginUser"))).getUid();
        //String username="xdzy12138";
        result=groupService.getGroupList_JSON(uid);
        return "success";
    }


    public String addGroup(){
        groupService.addGroup(group);
        result="添加分组成功";
        return "success";
    }

    @Override
    public Group getModel() {
        return group;
    }
}
